package ModelLayer;
import java.util.ArrayList;



public class DVD
{
    // instance variables - replace the example below with your own
    private ArrayList<Copy> copyList;
    private int id;
    private String title;
    private String author;
    private String publicationDate;
   
    /**
     * Constructor for objects of class DVD
     */
    public DVD(int id, String title, String author, String publicationDate)
    {
        // initialise instance variables
        copyList = new ArrayList<Copy>();
        this.id = id;
        this.title = title;
        this.author = author;
        this.publicationDate = publicationDate;
    }
    public void setId(int newId)
    {
        id = newId;
    }
    public int getId()
    {
        return id;
    }
    public void setTitle(String newTitle)
    {
        title = newTitle;
    }
    public String getTitle()
    {
        return title;
    }
    public void setAuthor(String newArtist)
    {
         author= newArtist;
    }
    public String getAuthor()
    {
        return author;
    }
    public void setPublicationDate(String newPublicationDate)
    {
        publicationDate = newPublicationDate;
    }
    public String getPublicationDate()
    {
            return publicationDate;
    }   
    public void addCopy(Copy copy)
    {
        copyList.add(copy);
    }
    
    public Copy findCopy(int serialNumber)
    {
        boolean found= false;
        int index=0;
        while(index < copyList.size() && !found)
        {
            Copy copy= copyList.get(index);
            if(copy.getSerialNumber() == serialNumber)
            {
                found = true;
            }
            else{
                index++;
            }
        }//end while
        if(found) {
            return copyList.get(index);
        }
        else{
            return null;
        }
    }
    public void removeCopy(int serialNumber)
    {
        Copy copy = findCopy(serialNumber);
        copyList.remove(copy);
}
public void updateCopy( int serialNumber, String purchaseDate, double purchasePrice)
{
    
    Copy copy = findCopy(serialNumber);
    copy.setPurchaseDate(purchaseDate);
    copy.setPurchasePrice(purchasePrice);
    
}
public int showSizeOfCopyList()
{
    return copyList.size();
}
public void makeAListOfCopies()
{
    int size = showSizeOfCopyList();
    if(size > 0)
    for(Copy copy : copyList) 
        {
            System.out.println(copy.getPurchaseDate());
        }
        else
        {
            System.out.println("There are no copies of that dvd");
        }
}
    
}
